package PersonStu.sanqi;


import java.util.ArrayList;
import java.util.List;

/**
 * @Author：DijaH
 * @Date：2022/12/29 12:41 下午
 * @Version：1.0.0
 * @Description： 打印一个字符串的全部子序列
 */
public class code_19_PrintallSubSequence {

    public static List<String> subs(String s){
        char[] chars = s.toCharArray();
        String path = "";
        List<String> ans = new ArrayList<>();

        process1(chars,0,path,ans);
        return ans;

    }

    /**
     * 在chars[0...i-1]上已经走过了，都在path上
     * @param chars
     * @param index
     * @param path
     * @param ans
     */
    private static void process1(char[] chars, int index, String path, List<String> ans) {
        //对于当前的位置的字符，要么要，要么不要
        if(index == chars.length){
            ans.add(path);
            return;
        }
        //嫑
        process1(chars,index + 1,path,ans);
        process1(chars,index + 1,path + String.valueOf(chars[index]),ans);
    }

    public static void main(String[] args) {
        String str = "abc";
        List<String> subs = subs(str);
        for (String sub : subs) {
            System.out.println(sub);
        }
    }


}
